<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="isEdit ? '修改' : '新增'"
    width="800px"
    :visible.sync="visible"
  >
    <el-form
      :model="form"
      ref="form"
      :rules="rules"
      :label-position="labelPosition"
      label-width="120px"
    >
      <el-row :gutter="24">
        <el-col>
          <el-form-item label="兼职单位名称">
            <el-input v-model="form.unitName" placeholder="请输入兼职单位名称" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="兼职单位性质">
            <el-input v-model="form.unitNature" placeholder="请输入兼职单位性质" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="兼职职务">
            <el-input v-model="form.duty" placeholder="请输入兼职职务" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="组织批复文号">
            <el-input type="text" v-model="form.orgReplyNo" placeholder="请输入组织批复文号" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="年取酬(元)" prop="yearSalary">
            <el-input v-model.number="form.yearSalary" placeholder="请输入年取酬" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleUpdate">{{ isEdit ? '修改' : '新增' }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { openNotification, validateNum } from '@/utils/util'
export default {
  data() {
    return {
      isEdit: false,
      visible: false,
      form: {},
      labelPosition: 'right',
      inputWidth: {
        width: '100%'
      },
      rules: {
        yearSalary: validateNum
      },
      userRow: this.$route.params.userRow
    }
  },
  methods: {
    handleUpdate() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.visible = false
          this.$emit('refresh', this.form)
        }
      })
    },
    edit(bool, row) {
      this.isEdit = bool
      console.log('row', row)
      this.visible = true
      this.form = Object.assign({}, row)
    }
  }
}
</script>
